#include "coin.h"
#include<QTimer>
#include <QGraphicsScene>

const int speed = 200;

coin::coin(const QPixmap&pixmap,qreal coin_x,qreal coin_y,QObject* parent)
    :QObject(parent),QGraphicsPixmapItem(pixmap){
    setPos(coin_x,coin_y);//设置初始位置

    coinmove = new QPropertyAnimation(this, "pos");

    coinmove->setStartValue(QPointF(coin_x, coin_y));
    coinmove->setEndValue(QPointF(-50, coin_y));
    coinmove->setDuration((coin_x + 50)* 1000/speed);
    coinmove->start();
    connect(coinmove, &QPropertyAnimation::finished, this, [=]()
            {
        this->scene()->removeItem(this);
        this->deleteLater();
    });
}

void coin::setPos1(const QPointF &pos)
{
    m_pos = pos;
    this->setPos(m_pos);
}

